<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>申请咨询专家</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../res/layui/css/layui.css">
    <link rel="stylesheet" href="../../res/css/bootstrap.min.css">
    <script src="../../res/js/jquery-3.1.1.min.js" charset="utf-8"></script>
    <script src="../../res/js/Tools.js"></script>
    <script src="../../res/layui/layui.js"></script>
    <style>
        .layui-form-label{
            width: 100px;
        }
    </style>

    <script type="text/javascript">
        //全局同步
        $.ajaxSetup({
            async: false
        });
    </script>
    <script type="text/javascript">
        $(function () {
            var schemeId = getQueryString("schemeId");
            var sort = getQueryString("sort");//申请咨询状态
            $.ajax({
                url:"../../AtsSchemeController/selectExist",
                type:"post", // 传输类型
                data:{'schemeId' : schemeId},
                success:function(obj){
                    for(var i in obj){
                        if(sort == 20){  //领导已同意
                            $("#testListAction").html("领导已同意");
                            $("#testListAction").attr("class","layui-btn layui-btn-disabled");
                            $("#applyForExp").val(obj[i].applyForExp);
                            $("#applyForExp").attr("readonly","readonly");
                            $("#testListAction").attr("disabled","disabled");
                        }else if(sort == 21){ //领导已拒绝
                            $("#testListAction").html("领导已拒绝");
                            $("#testListAction").attr("class","layui-btn layui-btn-disabled");
                            $("#applyForExp").val(obj[i].applyForExp);
                            $("#applyForExp").attr("readonly","readonly");
                            $("#testListAction").attr("disabled","disabled");
                            $("#dianji").removeAttr("hidden");
                            // $("#again").removeAttr("hidden");
                        }else if(obj[i].auditState == 10){
                            $("#testListAction").html("已申请");
                            $("#testListAction").attr("class","layui-btn layui-btn-disabled");
                            $("#applyForExp").val(obj[i].applyForExp);
                            $("#applyForExp").attr("readonly","readonly");
                            $("#testListAction").attr("disabled","disabled");
                        }else if(obj[i].auditState == 30){
                            $("#testListAction").html("专家已获知待回复");
                            $("#testListAction").attr("class","layui-btn layui-btn-disabled");
                            $("#applyForExp").val(obj[i].applyForExp);
                            $("#applyForExp").attr("readonly","readonly");
                            $("#testListAction").attr("disabled","disabled");
                        }else if(obj[i].auditState == 40){
                            $("#testListAction").html("专家已回复");
                            $("#testListAction").attr("class","layui-btn layui-btn-disabled");
                            $("#applyForExp").val(obj[i].applyForExp);
                            $("#applyForExp").attr("readonly","readonly");
                            $("#testListAction").attr("disabled","disabled");
                        }

                    }
                    /*if(obj.auditState > 0){
                        $("#testListAction").html("已申请");
                        $("#testListAction").attr("class","layui-btn layui-btn-disabled");
                        $("#applyForExp").val(obj.applyForExp);
                        $("#applyForExp").attr("readonly","readonly");
                        $("#testListAction").attr("disabled","disabled");
                    }
*/
                },
                error:function(e){

                }

            });
            $("#schemeId").val(schemeId);
        });
    </script>
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>申请咨询专家</legend>
</fieldset>
<div><form class="layui-form" action="" id="inputForm" >
    <div class="layui-form-item">
        <label class="layui-form-label">方案名称</label>
        <div class="layui-input-block">
            <input type="text" name="schemeId" id ="schemeId" readonly="readonly" placeholder="方案id" autocomplete="off" class="layui-input" hidden>
            <input type="text" name="applyForTime" id ="applyForTime" readonly="readonly" placeholder="申请时间" autocomplete="off" class="layui-input" hidden>
            <input type="text" name="auditState" id ="auditState" readonly="readonly" placeholder="审核状态" value="10" autocomplete="off" class="layui-input" hidden>
            <input type="text" name="saName" readonly="readonly" id ="schemeName" lay-verify="required" autocomplete="off" class="layui-input" >
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">申请理由</label>
        <div class="layui-input-block">
            <!--<input type="text" name="resultEffect" id ="resultEffect" lay-verify="required" placeholder="请输入实施效果" autocomplete="off" class="layui-input" >-->
            <textarea name="applyForExp" id ="applyForExp" lay-verify="required" placeholder="请输入您的申请理由" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" id="testListAction" lay-filter="demo1">立即申请</button>
            <button type="button" id="dianji" class="layui-btn layui-btn-primary" onclick="again()" hidden>再次申请</button>
        </div>
    </div>
</form></div>

<script type="text/javascript">
    /**
     * 再次申请
     */
    function again(){
        $("#testListAction").html("申请");
        $("#testListAction").attr("class","layui-btn");
        $("#applyForExp").val("");
        $("#applyForExp").removeAttr("readonly");
        $("#testListAction").removeAttr("disabled");
        $("#dianji").attr("hidden","hidden");
    }
    /**
     * 关闭当前弹出层
     */
    function closeWindow(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
        parent.layui.table.reload('schemeId');
    }

</script>

<script>
    layui.use(['form', 'layedit', 'layer', 'laydate','tree','util','upload'], function(){
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , tree = layui.tree
            ,util = layui.util
            ,upload = layui.upload;

        form.render();
        laydate.render({
            elem: '#applyForTime',
            value: new Date(),
            type: 'datetime'
        });


        //监听提交
        form.on('submit(demo1)', function(data){
            var urles = "../../AtsSchemeController/atsSchemeExpertUpdateByPrimaryKeySelective?isva=0&schemeId="+$("#schemeId").val();
            $.post(urles,null);
            var urls = "../../AtsSchemeController/updateAuditState?sort=10&schemeId="+$("#schemeId").val();
            $.post(urls,null);
            var url = "../../AtsSchemeController/atsSchemeExpertInsert?isva=1";
            var formData = new FormData(document.getElementById("inputForm"));
            //传输路径
            $.ajax({
                url:url,
                type:"post", // 传输类型
                data:formData, // 数据
                async:false, // 全局同步
                processData:false,
                contentType:false,
                dataType:"json",
                success:function(obj){
                    // alert("操作成功");
                    //     layer.alert("操作成功");
                    layer.msg(obj.msg,{
                        icon:1,
                        time:1000,
                    },function(){
                        closeWindow();
                    });
                    return false ;


                },
                error:function(e){
                    layer.msg(obj.msg,{
                        icon:1,
                        time:1000,
                    },function(){
                        closeWindow();
                    });
                    return false ;
                }
            });

            return false ;


        });


    });

</script>
</body>
</html>